package com.qf.day03.loop;

import java.util.Scanner;

/**
 * 循环录入5个人人的成绩，求最大成绩、最小成绩、平均成绩
 */
public class GradesCompare {
    public static void main(String[] args) {
        System.out.println("请输入5次成绩(（0~100整数）)：");
        Scanner sc = new Scanner(System.in);
        int sum=0;
        int count = 0;
        int ave=0;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;

        for (int i = 1; i <= 5; i++) {
            int grade = sc.nextInt();
            if(grade<=100||grade>=0){
                sum+=grade;
                ++count;
                ave=sum/count;
                if(max<grade){
                    max=grade;
                }
                if(min>grade){
                    min=grade;
                }
            }else{
                System.out.println("输入错误");
                break;
            }

        }
        System.out.println("平均成绩为"+ave);
        System.out.println("最好成绩为："+max);
        System.out.println("最差成绩为："+min);
    }
}
